class D25 {
    constructor( p ){
        this.__target = p.target;
        this.__initSize = null;
        this.__2dwithin = {};
    }

    init( params ){
        const ref = params.refer;
        const w = ref.width, h=ref.height , z = $T.selectValue( params.h , 0);
        const startPos = $T.findChildNode('startpoint' , ref).getPosition(),
              endPos = $T.findChildNode("endpoint" , ref).getPosition();
        this._setWinthin( {x: w , y : startPos.y - endPos.y , z:h} );
        this.__initSize = {w : this.__target.node.width , 
                           h : this.__target.node.height , 
                           z : this.__target.node.height ,
                           stW : this.__target.node.width * (params.stW ? params.stW : .2),
                           stH : this.__target.node.height * (params.stH ? params.stH : .2),
                           toW : this.__target.node.width * (params.toW ? params.toW : 1),
                           toH : this.__target.node.height * (params.toH ? params.toH : 1),
                           stO : (params.stO ? params.stO : 255),
                           startPos : startPos,
                           endPos : endPos
        };
    }

    _setWinthin( p ){
        this.__2dwithin.x = p.x;
        this.__2dwithin.y = p.y;
        this.__2dwithin.z = p.z;
    }

    get25dPos( xr , yr , zr ){
        let target = this.__target;
        xr = $T.selectValue( xr , 0),
        yr = $T.selectValue( yr , 0),
        zr = $T.selectValue( zr , 0);
        let aY = target.node.anchorY ,
            aX = target.node.anchorX ,
            aZ = 0 ,
            x = this.__2dwithin.x,
            y = this.__2dwithin.y,
            z = this.__2dwithin.z; 
        let point = {x:x*xr , y:y*yr , z:z*zr} , 
            origin = {x:x*aX , y:y-y*aY , z:z*aZ};
        
        let d2pos = cc.v2( (point.x - origin.x)*(Math.cos(yr*.1)/1.5) ,  origin.y - point.y  + point.z * (Math.cos(yr*.1)/5) ),
            per = point.y/y;
        let size = { w : per * this.__initSize.w + this.__initSize.stW  , h : per * this.__initSize.h + this.__initSize.stH};
        let o = this.__initSize.stO + yr*(255-this.__initSize.stW);

        size.w = size.w > this.__initSize.toW ? this.__initSize.toW : size.w;
        size.h = size.h > this.__initSize.toH ? this.__initSize.toH : size.h;
        return {
            d2pos : d2pos , 
            size : size,
            opacity : o > 180 ? 255 : o
        }
    } 
    
}
module.exports = D25; 